package com.semnox.androidgame.test.image;

import com.semnox.androidgame.test.image.component.Speed;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Image {

	private Bitmap bitmap; //the actual bitmap
	private int x; //x coordinate
	private int y; //y coordinate
	private boolean touched; //if model is touched/ picked up

	private Speed speed;
	
	public Image(Bitmap bitmap, int x, int y) {
		this.bitmap = bitmap;
		this.x = x;
		this.y = y;
		speed = new Speed();
	}

	public Bitmap getBitmap() {
		return bitmap;
	}

	public void setBitmap(Bitmap bitmap) {
		this.bitmap = bitmap;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public boolean isTouched() {
		return touched;
	}

	public void setTouched(boolean touched) {
		this.touched = touched;
	}
	
	public void draw(Canvas canvas) {
		canvas.drawBitmap(bitmap, x-(bitmap.getWidth()/2), y-(bitmap.getHeight()/2), null);
	}

	public void handleActionDown (int eventX, int eventY) {
		if (eventX>=(x-bitmap.getWidth()/2) && (eventX<=(x+bitmap.getWidth()/2))) {
			if	(eventY>=(y-bitmap.getWidth()/2) && (eventY<=(y+bitmap.getWidth()/2))) {
				//image touched
				setTouched(true);
			} else {
				setTouched(false);
			} 
		} else {
			setTouched(false);
		}
	}
	
	public void update() {
		if (!touched) {
			x+=(speed.getXv()*speed.getxDirection());
			y+=(speed.getYv()*speed.getyDirection());
		}
	}
	
	public Speed getSpeed() {
		return speed;
	}
}
